package com.example.websocket.pattern.structural.flyweight;

import java.util.HashMap;

public class ShapeFactory {

    private static final HashMap<String, Shape> circleMap = new HashMap<>();

    public static Shape getCircle(String color){
        Circle circle = (Circle) circleMap.get(color);

        if (circle == null) {
            circle = new Circle(color);
            circleMap.put(color, circle);
            System.out.println("Creating circle of color: " + color);
        }
        return circle;
    }

    public static void showMap(){
        for (Shape c : circleMap.values()){
            Circle circle = (Circle) c;
            circle.draw();
        }
    }
}
